using System.Collections.Generic;
using System.Linq;
using UnityEngine;

[CreateAssetMenu(fileName = "Effect26-目标棋子攻击力翻倍", menuName = "Skill/Effect/Effect26-目标棋子攻击力翻倍", order = 26)]
public class Effect26 : EffectBase
{
    private Dictionary<Chess,int> RecordingChessDic = new();
    public override void Apply(Pair pair, GameEvent e, List<Chess> targets)
    {
        if(targets == null || targets.Count == 0) return;

        foreach (var target in targets)
        {
            if (RecordingChessDic.ContainsKey(target) == false)
            {
                RecordingChessDic.Add(target,target.ChessDetail.Attack);
            }
            
            target.Buff(RecordingChessDic[target]);
        }
    }
    
    public override void RemoveDictionary(Pair pair)
    {
        if(RecordingChessDic.ContainsKey(pair.Chess))
        {
            foreach (var chess in RecordingChessDic.Keys.ToList())
            {
                ExternallyFunctions(chess);
                RecordingChessDic.Remove(pair.Chess);
            }
        }
    }

    public override void ExternallyFunctions(Chess chess)
    {
        if (!RecordingChessDic.TryGetValue(chess, out var value)) return;
        chess.Buff(-value);
        RecordingChessDic.Remove(chess);
    }
}